package com.cin.cma.server.pos.controller;


import cn.hutool.core.date.DateUtil;
import com.cin.cma.common.model.ApiResponse;
import com.cin.cma.common.model.finixx.base.BaseRequest;
import com.cin.cma.common.model.finixx.base.BaseResponse;
import com.cin.cma.common.model.finixx.request.*;
import com.cin.cma.common.model.finixx.response.*;
import com.cin.cma.server.biz.model.core.request.SeatSalesRequestCO;
import com.cin.cma.server.biz.controller.CoreController;
import com.cin.cma.server.pos.service.ITicketService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @Date：2024/7/19 18:27
 */
@RestController
@RequestMapping("ticket")

public class TicketController {
    @Autowired
    private ITicketService ticketService;

    @Autowired
    CoreController coreController;

    /**
     * 获取全天排期信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getSession")

    public ApiResponse<SessionResponse> getSession(@RequestBody @Valid SessionRequest model) throws Exception {
        return ApiResponse.success(ticketService.getSession(model));
    }

    /**
     * 获取排期影片信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getSessionFilms")

    public ApiResponse<SessionFilmResponse> getSessionFilms(@RequestBody @Valid SessionFilmRequest model) throws Exception {
        return ApiResponse.success(ticketService.getSessionFilms(model));
    }
    @PostMapping("getUnSaleSeat")
    public ApiResponse<SeatSalesResponse> getUnSaleSeat(String sectionCode,String featureDate,String scheduleKey,String hallCode,String cinemaLinkId) throws Exception {

        SeatSalesRequestCO seatSalesRequestCO = new SeatSalesRequestCO();
        seatSalesRequestCO.setSectionCode(sectionCode);
        seatSalesRequestCO.setShowStartTime(DateUtil.parseDateTime(featureDate));
        seatSalesRequestCO.setScheduleKey(scheduleKey);
        seatSalesRequestCO.setHallCode(hallCode);
        seatSalesRequestCO.setCinemaLinkId(cinemaLinkId);

        ApiResponse<SeatSalesResponse> apiResponse = coreController.ticketGetSessionSeats(seatSalesRequestCO);
        return apiResponse;
    }
    /**
     * 获取影厅信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getHalls")

    public ApiResponse<HallsResponse> getHalls(@RequestBody @Valid BaseRequest model) throws Exception {
        return ApiResponse.success(ticketService.getHalls(model));
    }

    /**
     * 获取场区信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getSections")

    public ApiResponse<SectionsResponse> getSections(@RequestBody @Valid SectionsRequest model) throws Exception {
        return ApiResponse.success(ticketService.getSections(model));
    }

    /**
     * 获取座位图座位信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getSeatPlan")

    public ApiResponse<SeatPlanResponse> getSeatPlan(@RequestBody @Valid SectionsRequest model) throws Exception {
        return ApiResponse.success(ticketService.getSeatPlan(model));
    }

    /**
     * 获取排期价格政策
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getSessionPricePolicy")

    public ApiResponse<SessionPricePolicyResponse> getSessionPricePolicy(@RequestBody @Valid SessionPricePolicyRequest model) throws Exception {
        return ApiResponse.success(ticketService.getSessionPricePolicy(model));
    }

    /**
     * 获取订单号
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getBookingId")

    public ApiResponse<BookingIdResponse> getBookingId(@RequestBody @Valid BaseRequest model) throws Exception {
        return ApiResponse.success(ticketService.getBookingId(model));
    }

    /**
     * 锁座
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("repositionSeats")

    public ApiResponse<RepositionSeatsResponse> repositionSeats(@RequestBody @Valid RepositionSeatsRequest model) throws Exception {
        return ApiResponse.success(ticketService.repositionSeats(model));
    }

    /**
     * 释放座位
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("releaseSeats")

    public ApiResponse<RepositionSeatsResponse> releaseSeats(@RequestBody @Valid RepositionSeatsRequest model) throws Exception {
        return ApiResponse.success(ticketService.releaseSeats(model));
    }

    /**
     * 获取场次不可售座位
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getAllocateSeats")

    public ApiResponse<SeatSalesResponse> getAllocateSeats(@RequestBody @Valid SeatsRequest model) throws Exception {
        return ApiResponse.success(ticketService.getAllocateSeats(model));
    }

    /**
     * 获取订单确认号
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getConfirmId")

    public ApiResponse<ConfirmIdResponse> getConfirmId(@RequestBody @Valid BaseRequest model) throws Exception {
        return ApiResponse.success(ticketService.getConfirmId(model));
    }

    /**
     * 通过订单号获取订单信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("queryOrder")

    public ApiResponse<QueryOrderResponse> queryOrder(@RequestBody @Valid QueryOrderRequest model) throws Exception {
        return ApiResponse.success(ticketService.queryOrder(model));
    }

    /**
     * 通过取票号获取订单信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getBookingBill")

    public ApiResponse<BookingBillResponse> getBookingBill(@RequestBody @Valid BookingBillRequest model) throws Exception {
        return ApiResponse.success(ticketService.getBookingBill(model));
    }

    /**
     * 通过订单号获取影票信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getTickets")

    public ApiResponse<TicketsResponse> getTickets(@RequestBody @Valid TicketsRequest model) throws Exception {
        return ApiResponse.success(ticketService.getTickets(model));
    }

    /**
     * 退票
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("refund")

    public ApiResponse<BaseResponse> refund(@RequestBody @Valid RefundRequest model) throws Exception {
        return ApiResponse.success(ticketService.refund(model));
    }

    /**
     * 获取会员卡价格政策
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("cardPricePolicy")

    public ApiResponse<SessionPricePolicyResponse> cardPricePolicy(@RequestBody @Valid CardPricePolicyRequest model) throws Exception {
        return ApiResponse.success(ticketService.cardPricePolicy(model));
    }

    /**
     * 获取影片图片
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("filmImage")

    public ApiResponse<FilmImageResponse> filmImage(@RequestBody @Valid FilmImageRequest model) throws Exception {
        return ApiResponse.success(ticketService.filmImage(model));
    }
}
